/*
 * Auth Class
 */
(function(){
	S.auth = {};
	S.auth.sessid = null;
	S.auth.user = "candidate1";
	S.auth.password = "Siempre7@@";
	
	// Creates new session
	S.auth.createSession = function(_args) {
		S.Xhr({
		    onload: function(e) {
		        // this.responseText holds the raw text return of the message (used for JSON)
		        // this.responseXML holds any returned XML (used for SOAP web services)
		        // this.responseData holds any returned binary data
		        Ti.API.debug(this.responseText);
				S.json = JSON.parse(this.responseText);
		        S.auth.sessid = S.json.sessid;
		        S.auth.requestLogin({force:_args.force});
		    },
		    onerror: function(e) {
		        Ti.API.debug(e.error);
		        alert(e.error);
		    },
		    method: "POST",
		    url: "http://platform.electiontools.org:80/drupal6/?q=api/system/connect.json"
		});
	};
	
	// Logs in the user
	S.auth.requestLogin = function(_args) {
		S.Xhr({
		    onload: function(e) {
		        // this.responseText holds the raw text return of the message (used for JSON)
		        // this.responseXML holds any returned XML (used for SOAP web services)
		        // this.responseData holds any returned binary data
		        Ti.API.debug(this.responseText);
				S.ui.initInterface({force:_args.force})
		    },
		    onerror: function(e) {
		        Ti.API.debug(e.error);
		        alert(e.error);
		    },
		    method: "POST",
		    url: "http://platform.electiontools.org:80/drupal6/?q=api/user/login.json",
		    params: {
		    	'contentType': 'application/x-www-form-urlencoded',
				'username': S.auth.user,
				'password': S.auth.password,
				'sessid': S.auth.sessid
			}
		});
	};
	
	// Logout
	S.auth.requestLogout = function(_args) {

	};
	
	
}());